% A1 = [1    ,3.554           ;8.94338            ,7.00314            ];
% B1 = [99   ,0.554458757     ];%3.9433845634       ,192.00311465414    ];
% 
% fixed_point_calculation_vector1(A1,B1,"add",8,24,"Fixed");
function result = fixed_point_calculation_vector(Operand , Operator, Operation , Int_num , Fixed_num,Fixed_type)

    if(Fixed_type == "Fixed")
        %% 定点化处理输入（向量化）
        fixed_operand   = fix(Operand  .* 2^Fixed_num);
        fixed_operator  = fix(Operator .* 2^Fixed_num);

        %% 输入限幅,做溢出处理
        max_val = 2^(Fixed_num+Int_num);
        fixed_operand(fixed_operand >  max_val) = fixed_operand(fixed_operand >  max_val) - max_val;
        fixed_operator(fixed_operator > max_val) = fixed_operator(fixed_operator > max_val) - max_val;

        %% 定点运算
        switch lower(Operation)
            case 'add'
                result_fixed = fixed_operand + fixed_operator;
            case 'sub'
                result_fixed = fixed_operand - fixed_operator;
            case 'mul'
                result_fixed = fix(fixed_operand .* fixed_operator / 2^Fixed_num);
            case 'div'
                result_fixed = fix((fixed_operand * 2^Fixed_num) ./ fixed_operator);
            otherwise
                error("Fixed_point_calculation Operation Error");
        end

        %% 直接还原为浮点数
        result = result_fixed ./ 2^Fixed_num;
    else
        switch lower(Operation)
            case 'add'
                result = Operand + Operator     ;
            case 'sub'
                result = Operand - Operator     ;
            case 'mul'
                result = Operand .* Operator    ;
            case 'div'
                result = Operand ./ Operator    ;
            otherwise
                error("Float_point_calculation Operation Error");
        end
    end

end
